package com.quanshi.shopping_order_customer_api.controller;

import com.quanshi.shopping_common.entity.Orders;
import com.quanshi.shopping_common.result.BaseResult;
import com.quanshi.shopping_common.service.IOrderService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单管理
 */
@RestController
@RequestMapping("/user/orders")
public class OrderController {


    @DubboReference
    private IOrderService orderService;

    /**
     * 添加订单
     *
     * @param orders 订单对象
     * @return
     */
    @PostMapping("/add")
    public BaseResult add(@RequestHeader Long userId,@RequestBody Orders orders) {
        //设置订单的用户id
        orders.setUserId(userId);
        orderService.add(orders);
        return BaseResult.success();
    }

    /**
     * 根据id查询订单信息
     *
     * @param id 订单id
     * @return
     */
    @GetMapping("/findById")
    public BaseResult findById(String id) {
        Orders orders = orderService.findById(id);
        return BaseResult.success(orders);
    }

    /**
     * 查询登录用户指定状态的订单列表
     * @param userId 用户id
     * @param status 订单状态 1、未付款，2、已付款，3、未发货，4、已发货，5、交易成功，6、交易关闭,7、待评价
     * @return
     */
    @GetMapping("/findUserOrders")
    public BaseResult findUserOrders(@RequestHeader Long userId, String status) {
        List<Orders> userOrders = orderService.findUserOrders(userId, status);
        return BaseResult.success(userOrders);
    }
}
